package com.example.qxapp.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.qxapp.Bean.User;
import com.example.qxapp.R;

import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

public class zcActivity extends AppCompatActivity {
    private EditText username,password,repassword,nickname;
    private TextView dl;
    private Button zc;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zc);
        init();
        dl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(zcActivity.this, dlActivity.class));
            }
        });
        zc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                User user=new User();
                user.setUsername(username.getText().toString().trim());
                user.setPassword(password.getText().toString().trim());
                user.setNickname(nickname.getText().toString().trim());
                if (username.getText().toString().equals("")){
                    Toast.makeText(zcActivity.this,"用户名不得为空",Toast.LENGTH_SHORT).show();
                }else if (password.getText().toString().equals("")){
                    Toast.makeText(zcActivity.this,"密码不得为空",Toast.LENGTH_SHORT).show();
                }else if (!(password.getText().toString().equals(repassword.getText().toString()))){
                    Toast.makeText(zcActivity.this,"两次输入的密码不同",Toast.LENGTH_SHORT).show();
                }else {
                    user.signUp(new SaveListener<User>() {
                        @Override
                        public void done(User u, BmobException e) {
                            if (e==null){
                                Toast.makeText(zcActivity.this,"注册成功",Toast.LENGTH_SHORT).show();
                                finish();
                            }else {
                                Toast.makeText(zcActivity.this,"注册失败",Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
                }

            }
        });
    }
    void init(){
        username=findViewById(R.id.username);
        password=findViewById(R.id.password);
        repassword=findViewById(R.id.repassword);
        nickname=findViewById(R.id.nickname);
        dl=findViewById(R.id.dl);
        zc=findViewById(R.id.zc);
    }
}
